package hu.ikti.oamadmin.types.entities;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "GATEWAY")
@SequenceGenerator(sequenceName = "GATEWAY_SEQ", name = "GAT_SEQ", allocationSize = 1)
public class Gateway {

	private Long id;
	private Address address;
	private List<Bundle> bundles;

	public Gateway() {
	}

	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "GAT_SEQ")
	public Long getId() {
		return id;
	}

	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ADDRESS_FK")
	public Address getAddress() {
		return address;
	}

	@OneToMany(fetch = FetchType.LAZY)
	@JoinColumn(name = "GATEWAY_FK")
	public List<Bundle> getBundles() {
		return bundles;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public void setBundles(List<Bundle> bundles) {
		this.bundles = bundles;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Gateway other = (Gateway) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
